/*
 * Conferences Class for the program
 * Authors:  Ching-Ting Huang, Daniel Henderson
 * TCSS 360 Spring 2013 
 * University of Washington
 */
package View;


import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.Frame;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.GridLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.io.DataInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.List;

import javax.swing.BorderFactory;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JDialog;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.SwingUtilities;
import Model.Conference;
import Model.Controller;
import Model.Deadline;
import Model.Paper;
import Model.User;

import com.toedter.calendar.JDateChooser;

/**
 * This class is a member of the TabPanel: Conferences. It contains a scroll pane
 * of conferences, labels detailing who is the program chair of that conference
 * as well as the paper submission deadline for that conferences. Lastly two buttons
 * that will provide the functionality of 1) creating new conference is the user is
 * admin and 2) submitting a new manuscript.
 * 
 * @author Ching-Ting Huang, Daniel Henderson
 * @version UWTCSS 360, Spring 2013. 3-squared-software-systems.
 */
public class Conferences extends JPanel {
	
	private static final long serialVersionUID = -3707150214483287534L;
	private Controller controller;
	private ScrollPane scroll;
	private JLabel pc_name;
	private JLabel deadline;
	private Conference currentConference;
	private JTextField lblDeadlinePrint;
	private JTextField lblFilePathPrint;
	private JComboBox confComboList;
	private JTextField txtPTitle;
	private JTextField txtCategory;
	private JTextField txtKeywords;
	private JTextArea txtAbstract;
	private File theFile;
	private boolean hasFile;
	private Frame frame;
	private Paper currentPaper;
	byte [] encoded;

	/**
	 * Constructor for the Conferences class.
	 * 
	 * @param control is the Controller in the Model package.
	 */
	public Conferences(final Controller control) {
		controller = control;
		scroll = new ScrollPane(controller, "conf");
		pc_name = new JLabel("(Select a conference to see the Program Chair)");
		deadline = new JLabel("(YYYY/MM/DD)");
		setup();
	} //Conferences

	/**
	 * Adds components onto the panel such as the containers of labels and buttons.
	 * As well as setting up mouse listener for mouse clicks in order to update
	 * the label that will display the program chair and the paper submission deadline
	 * when individual conferences is being clicked in the scroll pane.
	 * 
	 * @author Ching-Ting Huang
	 */
	private void setup() {
		final JLabel flag = new JLabel("conf");

		/*
		  Using property change listener to catch list selection changes in ScrollPane.
		  By passing in JLabel to ScrollPane, if setText is changed, JLabels on 
		  Conferences tab will change accordingly.
		 */
		flag.addPropertyChangeListener(new PropertyChangeListener(){
			@Override
			public void propertyChange(PropertyChangeEvent e) {
				if (e.getSource() == flag) {
					Object[] data = scroll.getRow(scroll.getSelectedRowNum());

					for (Conference conf : controller.getConferenceList()) {
						if (conf.getConferenceName().equals(data[1])) {
							pc_name.setText(conf.getProgramChair().getfullname());
							int day = conf.getPaperRevisionSubmissionDeadline().getDateDay();
							int month = conf.getPaperRevisionSubmissionDeadline().getDateMonth();
							int year = conf.getPaperRevisionSubmissionDeadline().getDateYear();
							deadline.setText(year + "/" + month + "/" + day);
						}
					}
				}
			} //propertyChange
		});

		scroll.setFlag(flag);
		JScrollPane pane = scroll.getScrollPane();
		pane.setWheelScrollingEnabled(true);

		setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
		add(pane);
		add(getPCLbl());
		add(getDateLbl());
		add(getBtn());
	} //setup

	/**
	 * Sets up the buttons for 1) create conference and 2) submit paper and
	 * add them onto the container to be added to the panel.
	 * 
	 * @author Daniel Henderson
	 * 			Submit paper listener and functionality
	 * 
	 * @author Ching-Ting Huang
	 * 			Create Conference listener and functionality
	 * 
	 * @return the container containing the buttons.
	 */
	private Container getBtn() {
		Container flow = new JPanel(new FlowLayout(FlowLayout.CENTER));
		final JButton createConf = new JButton("Create Conference");
		final JButton submitPper = new JButton("Submit Paper");

		if (controller.getCurrentUsername().equals("admin")) {
			createConf.setVisible(true);
		} else {
			createConf.setVisible(false);
		}

		//Author Ching-Ting Huang Create Conference Listener
		createConf.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				if (e.getSource() == createConf) {
					//User input stored here
					Object[] data = new Object[7];

					//Create conference dialog
					NewConference dialog = new NewConference
							((JFrame) SwingUtilities.windowForComponent(createConf),
									"MSEE - Create A Conference", controller);

					dialog.start(data);
					data = dialog.getData();

					boolean flag = true;
					for (int i = 0; i < data.length; i++) {
						if (data[i] == null) {
							flag = false;
						}
					}
					if (flag) {
						dialog.dispose();
						//Conference date
						Calendar confTime = (Calendar)data[1];
						int confDay = confTime.get(Calendar.DATE);
						int confMon = confTime.get(Calendar.MONTH) + 1;
						int confYear = confTime.get(Calendar.YEAR);
						Deadline confDate = new Deadline(confMon, confDay, confYear);

						//Paper submission deadline
						Calendar pperTime = (Calendar)data[2];
						int pperDay = pperTime.get(Calendar.DATE);
						int pperMon = pperTime.get(Calendar.MONTH) + 1;
						int pperYear = pperTime.get(Calendar.YEAR);
						Deadline pperDate = new Deadline(pperMon, pperDay, pperYear);

						//Review submission deadline
						Calendar revTime = (Calendar)data[3];
						int revDay = revTime.get(Calendar.DATE);
						int revMon = revTime.get(Calendar.MONTH) + 1;
						int revYear = revTime.get(Calendar.YEAR);
						Deadline revDate = new Deadline(revMon, revDay, revYear);

						//Recommendation submission deadline
						Calendar reccTime = (Calendar)data[4];
						int reccDay = reccTime.get(Calendar.DATE);
						int reccMon = reccTime.get(Calendar.MONTH) + 1;
						int reccYear = reccTime.get(Calendar.YEAR);
						Deadline reccDate = new Deadline(reccMon, reccDay, reccYear);

						//Paper approval deadline
						Calendar aprvTime = (Calendar)data[5];
						int aprvDay = aprvTime.get(Calendar.DATE);
						int aprvMon = aprvTime.get(Calendar.MONTH) + 1;
						int aprvYear = aprvTime.get(Calendar.YEAR);
						Deadline aprvDate = new Deadline(aprvMon, aprvDay, aprvYear);

						User pc = (User)data[6];
						final Conference conf = new Conference((String)data[0], 
								pc,
								confDate, 
								pperDate, 
								revDate, 
								reccDate, 
								aprvDate);

						Object[] addItem = new Object[]{"" + confMon + "/" + confDay + "/" + confYear,
								(String)data[0], pc.getfullname()};
						controller.addConferenceToSystem(conf);
						pc.setPermission(3, true);
						scroll.addToTable(addItem);
					}
				}
			}
		});

		if (controller.getCurrentUsername().equals("admin")) {
			submitPper.setVisible(false);
		} else {
			submitPper.setVisible(true);
		}

		//Author Daniel Henderson - Submit Paper Listener
		submitPper.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				lblFilePathPrint = new JTextField();

				//Paper title Setup
				JLabel lblPaperTitle = new JLabel("Paper Title: ");
				txtPTitle = new JTextField();

				//Deadline Setup
				JLabel lblDeadline = new JLabel("Submission Deadline: ");
				lblDeadlinePrint = new JTextField("");
				lblDeadlinePrint.setEditable(false);
				lblDeadlinePrint.setBackground(Color.WHITE);
				lblDeadlinePrint.setBorder(txtPTitle.getBorder());

				//Conference Chooser Setup
				JLabel lblConf = new JLabel("Conference: ");

				//Category Setup
				JLabel lblCategory = new JLabel("Category: ");
				txtCategory = new JTextField();

				//Keywords Setup
				JLabel lblKeywords = new JLabel("Keywords: ");
				txtKeywords = new JTextField();

				//Abtract Text Area setup (100 words max)
				JLabel lblAbstract = new JLabel("Abstract: ");
				txtAbstract = new JTextArea(5, 20);
				txtAbstract.setBorder(txtPTitle.getBorder());

				//Path Setup
				JLabel lblFilePath = new JLabel("File Path: ");
				lblFilePathPrint = new JTextField("");
				lblFilePathPrint.setEditable(false);
				lblFilePathPrint.setBackground(Color.WHITE);
				lblFilePathPrint.setBorder(txtPTitle.getBorder());

				//Setup Submit Button
				JButton btnSubmit = new JButton("Submit");		

				//Setup Select Paper
				JButton btnSelectPaper = new JButton("Select Paper");	

				//Setup Submit Paper Window
				if (e.getSource() == submitPper) {
					int day = 0;
					int month = 0;
					int year = 0;
					Calendar today = Calendar.getInstance();
					int cur_date = today.get(Calendar.DATE);
					int cur_mon = today.get(Calendar.MONTH) + 1;
					int cur_yr = today.get(Calendar.YEAR);

					currentConference = null;
					final List<Conference> theConferences = controller.getConferenceList();
					List <String> conferencenames = new ArrayList<String>();
					Conference tempConference;

					//Populate the Conference String list for the Conference JComboBox
					for(int i = 0; i < theConferences.size(); i++) {
						tempConference = theConferences.get(i);
						Deadline paperSubmissionDeadline = tempConference.getPaperSubmissionDeadLine();
						day = paperSubmissionDeadline.getDateDay();
						month = paperSubmissionDeadline.getDateMonth();
						year = paperSubmissionDeadline.getDateYear();
						if (cur_yr == year) {
							if (cur_mon < month) {
								conferencenames.add(tempConference.getConferenceName());
							} else if (cur_mon == month) {
								if (cur_date <= day) {
									conferencenames.add(tempConference.getConferenceName());
								}
							}
						} else if (cur_yr < year) {
							conferencenames.add(tempConference.getConferenceName());
						}
					}
					String[] conferences = Arrays.copyOf(conferencenames.toArray(), conferencenames.size(), String[].class);
					/*Added this for below code I edited - Ching-Ting*/
					final Object[] conf = conferences;


					confComboList = new JComboBox(conferences);
					confComboList.setSelectedItem(null);
					confComboList.addActionListener(new ActionListener(){

						@Override
						public void actionPerformed(ActionEvent e) {
							JComboBox cb = (JComboBox) e.getSource();
							if (cb == confComboList) {
								int conferIndex = cb.getSelectedIndex();
								String conf_name = null;
								for (int i = 0; i < conf.length; i++) {
									if (i == conferIndex) {
										conf_name = (String)conf[i];
									}
								}
								for (int j = 0; j < theConferences.size(); j++) {
									if (conf_name.equals(theConferences.get(j).getConferenceName())) {
										currentConference = theConferences.get(j);
									}
								}
								lblDeadlinePrint.setText(currentConference.getPaperSubmissionDeadLine().toString());
							}

						}});
					JPanel panel = new JPanel();
					GridBagLayout gridbag = new GridBagLayout();
					GridBagConstraints c = new GridBagConstraints();
					panel.setLayout(gridbag);

					//Set GridBag constraints
					c.gridwidth = GridBagConstraints.REMAINDER; //last
					c.anchor = GridBagConstraints.WEST;
					c.weightx = 1.0;
					panel.setBorder(
							BorderFactory.createCompoundBorder(
									BorderFactory.createTitledBorder("Submit Paper"),
									BorderFactory.createEmptyBorder(5,5,5,5)));
					frame = new JFrame();
					JDialog dialog = new JDialog(frame, 
							"Submit A Paper",
							true);
					dialog.setContentPane(panel);
					Dimension windowSize = new Dimension(500, 500);
					frame.setPreferredSize(windowSize);
					dialog.setPreferredSize(windowSize);
					dialog.setDefaultCloseOperation(
							JDialog.DO_NOTHING_ON_CLOSE);



					GridBagConstraints labelConstraints = new GridBagConstraints();
					labelConstraints.insets = new Insets(10,0,0,0);
					labelConstraints.anchor = GridBagConstraints.EAST;
					labelConstraints.gridwidth = GridBagConstraints.RELATIVE; //next-to-last
					labelConstraints.fill = GridBagConstraints.NONE;      //reset to default
					labelConstraints.weightx = 0.0;                       //reset to default

					GridBagConstraints textConstraints = new GridBagConstraints();
					textConstraints.insets = new Insets(10,0,0,0);
					textConstraints.anchor = GridBagConstraints.EAST;
					textConstraints.gridwidth = GridBagConstraints.REMAINDER;     //end row
					textConstraints.fill = GridBagConstraints.HORIZONTAL;
					textConstraints.weightx = 1.0;


					//Add Conference Selection
					panel.add(lblConf, labelConstraints);
					panel.add(confComboList, textConstraints);

					//Add Deadline Display
					panel.add(lblDeadline, labelConstraints);
					panel.add(lblDeadlinePrint, textConstraints);

					panel.add(lblCategory, labelConstraints);
					panel.add(txtCategory, textConstraints);

					panel.add(lblPaperTitle, labelConstraints);
					panel.add(txtPTitle, textConstraints);

					panel.add(lblKeywords, labelConstraints);
					panel.add(txtKeywords, textConstraints);

					panel.add(lblAbstract, labelConstraints);
					panel.add(txtAbstract, textConstraints);

					panel.add(lblFilePath, labelConstraints);
					panel.add(lblFilePathPrint, textConstraints);

					btnSelectPaper.setPreferredSize(new Dimension(150, 25));
					btnSubmit.setPreferredSize(new Dimension(150, 25));
					textConstraints.fill = GridBagConstraints.VERTICAL;

					panel.add(btnSelectPaper, textConstraints);
					panel.add(btnSubmit, textConstraints);

					frame.add(panel);
					frame.setVisible(true);
					frame.setResizable(true);
					frame.pack();
					frame.setLocationRelativeTo(null);
					
					//Setup listener for Submit button. Author - Daniel Henderson
					btnSubmit.addActionListener(new ActionListener() {
						@Override
						public void actionPerformed(ActionEvent e) {
							if(!lblFilePathPrint.getText().isEmpty()) {
								encoded = new byte [16384]; 
								try {
									InputStream iStream = new FileInputStream(theFile.getPath());	
									DataInputStream dataIs = new DataInputStream(iStream);
									dataIs.readFully(encoded);
									dataIs.close();

								} catch (IOException e1) {
								}
								if(!txtPTitle.getText().isEmpty() || hasFile == true) {
									if(currentConference != null) {
										if(!txtCategory.getText().isEmpty()) {
											if(!txtKeywords.getText().isEmpty()) {
												if(!txtAbstract.getText().isEmpty()) {
													currentPaper = new Paper(theFile.getPath(), txtCategory.getText(), txtPTitle.getText(), 
															txtKeywords.getText(), txtAbstract.getText(), currentConference, controller.getCurrentUser());
													currentPaper.saveDigitalPaper(encoded);
													controller.submitPaper(currentPaper, currentConference);
													currentConference.getProgramChair().addPCPaper(currentPaper);
													controller.getCurrentUser().setPermission(0, true);
													controller.changedCurrentUserPermissions();
													JOptionPane.showMessageDialog(null, "Paper Submitted Successfully!");
													frame.dispose();
												}
												else {
													JOptionPane.showMessageDialog(null, "Please fill out the Abstraction section of this form."); 
												}

											}
											else {
												JOptionPane.showMessageDialog(null, "Please enter atleast one keyword pertaining to your paper."); 
											}

										}
										else {
											JOptionPane.showMessageDialog(null, "Please type in the category pertaining to your paper."); 
										}

									}
									else {
										JOptionPane.showMessageDialog(null, "Please select a conference to submit your paper to."); 
									}
								}
								else {
									JOptionPane.showMessageDialog(null, "Please type in the Title of your paper."); 
								}

								//
							}
							else {
								JOptionPane.showMessageDialog(null, "Please click the Select Paper button to choose the paper to submit."); 
							}
						}
					});

					btnSelectPaper.addActionListener(new ActionListener() {
						@Override
						public void actionPerformed(ActionEvent e) {
							JFileChooser fc = new JFileChooser();
							int returnVal = fc.showOpenDialog(pc_name);
							if (returnVal == JFileChooser.APPROVE_OPTION) {
								File file = fc.getSelectedFile();
								theFile = file;
								String thepath = file.getPath().toString();
								lblFilePathPrint.setText(thepath);
								hasFile = true;

							} else {
								System.out.println("Open command cancelled by user.");
							}
						}
					});

				}
			}

		});



		flow.add(createConf);
		flow.add(submitPper);
		return flow;
	} //getBtn

	/**
	 * Sets up the container for the 'program chair' labels on the panel.
	 * 
	 * @return the container containing the labels.
	 * @author Ching-Ting Huang
	 */
	private Container getPCLbl() {
		Container flow = new JPanel(new FlowLayout(FlowLayout.CENTER));
		final JLabel pcLbl = new JLabel("Program Chair: ");
		flow.add(pcLbl);
		flow.add(pc_name);
		return flow;
	} //getLbl

	/**
	 * Sets up the container for 'deadline' labels on the panel.
	 * 
	 * @return the container containing the labels.
	 * @author Ching-Ting Huang
	 */
	private Container getDateLbl() {
		Container flow = new JPanel(new FlowLayout(FlowLayout.CENTER));
		final JLabel dateLbl = new JLabel("Submission Deadline: ");
		flow.add(dateLbl);
		flow.add(deadline);
		return flow;
	} //getDateLbl

	/**
	 * Used to print out tab titles in tabbed pane.
	 */
	public String getName() {
		return "Conferences";
	} //getName


	//================ Private Inner Class: AddConference ======================//


	/**
	 * This dialog helps the user create a new conference by presenting text fields and
	 * date chooser to customize the conference: name, deadlines, designated program chair.
	 * 
	 * @author Ching-Ting Huang
	 * @version UWTCSS 360, Spring 2013. 3-squared-software-systems
	 */
	private class NewConference extends JDialog {

		/**
		 * 
		 */
		private static final long serialVersionUID = 2678356644655804792L;
		private final JButton confirm = new JButton("Confirm");
		private final JButton cancel = new JButton("Cancel");
		private Controller controller;
		private List<JLabel> label;
		private List<JDateChooser> dateChooser;
		private JTextField confName;
		private JComboBox pc;
		private Object[] obj;

		/**
		 * Sets up the dialog.
		 * 
		 * @param frame is the JFrame the program sits on.
		 * @param title is the title of the JDialog.
		 * @param control is the Controller in Model class.
		 */
		private NewConference(final JFrame frame, 
				final String title, 
				final Controller control) {
			super(frame, title);
			setResizable(false);
			controller = control;
			setup();
		} //NewConference

		/**
		 * This method creates the labels, date choosers, buttons and combo box for the UI
		 * and setting appropriate alignment to the panel.
		 * 
		 * @author Ching-Ting Huang
		 */
		private void setup() {
			JPanel main = new JPanel();
			
			pc = users();
			label = labels();
			dateChooser = dateChooser(5);
			Container title = header();
			Container buttons = getButtons();
			JPanel rest = labelNbutton(label, dateChooser, pc);

			main.setLayout(new BorderLayout());
			main.add(title, BorderLayout.NORTH);
			main.add(rest, BorderLayout.CENTER);
			main.add(buttons, BorderLayout.SOUTH);

			add(main);
			pack();
		} //setup

		/**
		 * The caller class calls this class to display the dialog box.
		 * 
		 * @param getObj is an empty array to be filled with user input from GUI.
		 * @author Ching-Ting Huang
		 */
		public void start(Object[] getObj) {
			obj = getObj;
			setModal(true);
			setLocationRelativeTo(null);
			setVisible(true);
		} //start

		/**
		 * Populates the object array with user's input from textfields and datechooser.
		 * 
		 * @author Ching-Ting Huang
		 */
		private void update() {
			obj[0] = confName.getText();
			for (int i = 0; i < dateChooser.size(); i++) {
				obj[i + 1] = dateChooser.get(i).getCalendar();
			}
			obj[obj.length - 1] = controller.getUserList().get(pc.getSelectedIndex());
		} //update

		/**
		 * Let other classes gets the updated, populated array of data.
		 * 
		 * @return the Object array with user input.
		 * @author Ching-Ting Huang
		 */
		public Object[] getData() {
			return obj;
		} //getData

		/**
		 * Adds necessary number of date chooser into a list.
		 * 
		 * @param count is the number of date chooser needed.
		 * @return the list of date choosers.
		 * @author Ching-Ting Huang
		 */
		private List<JDateChooser> dateChooser(final int count) {
			List<JDateChooser> list = new ArrayList<JDateChooser>();
			for (int i = 0; i < count; i++) {
				list.add(new JDateChooser("yyyy/MM/dd", "####/##/##", '_'));
			}
			return list;
		} //texts

		/**
		 * Adds labels to the list.
		 * 
		 * @return the list of labels.
		 * @author Ching-Ting Huang
		 */
		private List<JLabel> labels() {
			List<JLabel> list = new ArrayList<JLabel>();
			list.add(new JLabel("Name of Conference: "));
			list.add(new JLabel("Date of Conference (YYYY/MM/DD): "));
			list.add(new JLabel("Paper Submission Deadline (YYYY/MM/DD): "));
			list.add(new JLabel("Peer-Review Deadline (YYYY/MM/DD): "));
			list.add(new JLabel("Paper Recommendation Deadline (YYYY/MM/DD): "));
			list.add(new JLabel("Paper Approval Deadline (YYYY/MM/DD): "));
			list.add(new JLabel("Designated Program Chair: "));
			return list;
		} //labels

		/**
		 * Puts all labels and buttons onto a temporary JPanel in GridLayout.
		 * 
		 * @param label is the list of JLabels.
		 * @param dateChooser is the list of JDateChoosers.
		 * @param pc is the JComboBox for Program Chair choice.
		 * @return JPanel containing all the above JComponents.
		 * @author Ching-Ting Huang
		 */
		private JPanel labelNbutton(final List<JLabel> label, 
				final List<JDateChooser> dateChooser, 
				final JComboBox pc) {

			confName = new JTextField(25);
			JPanel pane = new JPanel();
			pane.setLayout(new GridLayout(7, 1));

			//create list of container for each pair of label and textfield/datechooser
			List<Container> containers = new ArrayList<Container>();
			for (int i = 0; i < 7; i++) {
				Container contain = new JPanel(new FlowLayout(FlowLayout.LEFT));
				containers.add(contain);
			}
			//add pair into their order of container
			for (int j = 0; j < containers.size(); j++) {
				containers.get(j).add(label.get(j));
				if (j == 0) {
					containers.get(j).add(confName);
				} else if (j == 6) {
					containers.get(j).add(pc);
				} else {
					containers.get(j).add(dateChooser.get(j - 1));
				}
			}
			//add containers onto panel
			for (int k = 0; k < containers.size(); k++) {
				pane.add(containers.get(k));
			}
			return pane;
		} //labelNbutton

		/**
		 * Sets up the title.
		 * 
		 * @return Container containing the title.
		 * @author Ching-Ting Huang
		 */
		private Container header() {
			Container grid = new JPanel(new FlowLayout(FlowLayout.LEADING));
			JLabel title = new JLabel("Create A New Conference");
			title.setFont(new Font("Serif", Font.BOLD + Font.ITALIC, 22));
			grid.add(title);
			return grid;
		} //header

		/**
		 * Sets up JButtons' action listener and add them to the panel to be
		 * added to the main panel.
		 * 
		 * @return the container containing two buttons with flow layout.
		 * @author Ching-Ting Huang
		 */
		private Container getButtons() {
			Container flow = new JPanel(new FlowLayout(FlowLayout.CENTER));
			confirm.addActionListener(new ActionListener() {
				@Override
				public void actionPerformed(ActionEvent e) {
					if (e.getSource() == confirm) {

						update();
						boolean check = true;
						for (int i = 0; i < obj.length; i++) {
							if (obj[i] == null) {
								check = false;
							}
						}
						if (!check) {
							JOptionPane.showMessageDialog(null, "Please make sure all fields are filled in.",
									"Incomplete Form", JOptionPane.ERROR_MESSAGE);
							setVisible(true);
						} else {
							setVisible(false);
						}
					}
				}
			});

			cancel.addActionListener(new ActionListener() {
				@Override
				public void actionPerformed(ActionEvent e) {
					if (e.getSource() == cancel) {
						dispose();
					}
				}
			});

			flow.add(confirm);
			flow.add(cancel);
			return flow;
		} //getButtons

		/**
		 * Adds all current users onto the JComboBox with scrolling capability.
		 * 
		 * @return the JComboBox with all users' name as its choice.
		 * @author Ching-Ting Huang
		 */
		private JComboBox users() {
			List<User> users = controller.getUserList();
			JComboBox box = new JComboBox();
			for (int i = 0; i < users.size(); i++) {
				box.addItem(users.get(i).getfullname());
			}
			return box;
		} //users
	} //Inner

} //Outer
